<?php
error_reporting(0);
/**
 * GameController
 * 
 * @author
 * @version 
 */
require_once 'Zend/Controller/Action.php';
class AccountController extends Sunnet_Controller_Action
{
	var $_arrParam;
    protected $domain = DOMAIN;
	public function init()
    {
        //      Truyền các tham số nhận được ra view
        $this->_arrParam = $this->_request->getParams();
        if (empty($this->_arrParam['page'])) {
            $this->_arrParam['page'] = 1;
        }
        if (empty($this->_arrParam['line_per_page'])) {
            $this->_arrParam['line_per_page'] = 10;
        }

        $this->view->arrParam = $this->_arrParam;
        $this->view->domain = $this->domain;
        $this->view->function = $this;
    }

    public function preDispatch(){
		$template_path = TEMPLATE_PATH . "/wap/default/";
		$this->loadTemplate($template_path,'template.ini','template');

         //set group main
        Zend_Loader::loadClass('Wap_Models_ControllerModel');
        $controllerModel = new Wap_Models_ControllerModel();       
        $this->view->groupmain_list = $controllerModel->listMenuGroupNote();
        $this->view->newsHots = $controllerModel->listNewsHotRight();
        $this->view->listBanners = $controllerModel->listBannerHeader();
    }


    public function indexAction (){

    }

    public function dangNhapAction (){
        //      Load js và css
        $this->view->headLink()->appendStylesheet('/css/style.css','screen');
        $this->view->headLink()->appendStylesheet('/css/verify.css','screen');


    }
    public function dangNhapHoSoAction (){
        //      Load js và css
        $this->view->headLink()->appendStylesheet('/css/style.css','screen');
        $this->view->headLink()->appendStylesheet('/css/verify.css','screen');


    }

    public function theoDoiHoSoAction (){
//      Load js và css
        $this->view->headLink()->appendStylesheet('/css/admin.css','screen');
        $this->view->headLink()->appendStylesheet('/css/style.css','screen');
        $this->view->headLink()->appendStylesheet('/css/verify.css','screen');

        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()){
            $identity = $auth->getIdentity();
            $user_id = $identity['UserID'];
        }else{
            // chuyen sang trang thong bao
            $this->_redirect('/account/dang-nhap-ho-so');  
        }

        //list ho so ra day
        Zend_loader::loadClass('Wap_Models_HoSoModel');
//      Load các model và form sử dụng trong action
         $db = new Wap_Models_HoSoModel();
         $listpage = $db->listpage($user_id);
         $currentPage = 1;       
        $i = $this->_getParam('page',1);
        if(!empty($i))
        {
            $currentPage = $i;
        }
        $paginator = Zend_Paginator::factory($listpage);
        $paginator->setItemCountPerPage(10)
        ->setPageRange(4)
        ->setCurrentPageNumber($currentPage);
        $this->view->paginator = $paginator; 


    }

    //code date time
    public function convertTimeAgo ($activity_time){       
       $timeinsecond = time() - $activity_time;
       if($timeinsecond >=0){
         $minus  = abs(floor(($timeinsecond%3600)/60));
         $hour   =   abs(round(($timeinsecond-$minus*60)/3600,0));              
          
         $timematch = 0;
         if($timeinsecond<60){
            $timematch = $timeinsecond." giây trước";  
            return $timematch;
         }elseif(60<$timeinsecond && $timeinsecond<3600){
            $timematch = $minus." phút trước";      
            return $timematch;       
         }elseif(3600<=$timeinsecond && $timeinsecond<86400){
            $timematch = $hour." giờ trước"; 
            return $timematch;
         }elseif(86400<=$timeinsecond && $timeinsecond<518400){
            $timematch =  abs(round(($hour/24))) . " ngày trước";
            return $timematch;
         }else {
            $timematch= date('d/m/Y', $activity_time);
            return $timematch;
         }
         return $timematch;
       }
    }
    function cut_substr($str,$n)
    {       
        $str = strip_tags($str);   
        $str = trim($str);    
       // ----- remove control characters ----- 

        $str = str_replace("\r", '<br/>', $str);    // --- replace with empty space
        $str = str_replace("\n", '', $str);   // --- replace with space
        $str = str_replace("\t", '', $str);   // --- replace with space
        // ----- remove cac br lien tiep ----- 
        $str = preg_replace('#(<br */?>\s*)+#i', '<br />', $str);

        $html = substr($str,0,$n);
        $html = substr($html,0,strrpos($html,' '));

        return $html.'...';
    }  

    function cut_substr_strip($str)
    {                   
        $str = strip_tags($str);   
        $str = trim($str);    
       // ----- remove control characters ----- 

        $str = str_replace("\r", '<br/>', $str);    // --- replace with empty space
        $str = str_replace("\n", '', $str);   // --- replace with space
        $str = str_replace("\t", '', $str);   // --- replace with space
        // ----- remove cac br lien tiep ----- 
        $str = preg_replace('#(<br */?>\s*)+#i', '<br />', $str);

        return $str;

    }  

}
